Everything Totally Explained


Ask & we'll explain, totally!
Identity column
Totally Explained


  NEW! All the latest news in the worlds of computer gaming, entertainment, the environment,  
finance, health, politics, science, stocks & shares, technology and much, much, more.  


    View this entry using RSS
   

Everything about Identity Column totally explained

An Identity column is a column (also known as a field ) in a database table that (1) uniquely identifies every row in the table, and (2) is made up of values generated by the database. This is much like an AutoNumber field in Microsoft Access or a sequence in Oracle. Because the concept is so important in database science, all RDBMS systems implement some type of generated key, although each has its own terminology. An identity column differs from a primary key in that its values are managed by the server and (except in rare cases ) can't be modified. In many cases an identity column is used as a primary key, however this isn't always the case.
   Two types of identity columns are available in SQL Server: incremental (where the user can set a seed and an increment ) and random (where the server chooses a random numeric value and ensures that it hasn't already been used ).

Code Samples

Create Table Contacts ( FirstName varChar(30), LastName varChar(30), Phone varChar(16), ContactID identity(1, 1) ) or Create Table Contacts ( FirstName varChar(30), LastName varChar(30), Phone varChar(16) ) GO Alter Table Contacts Add ContactID identity(1, 1)

Related Functions

It is often useful or necessary to know what identity value was generated by an INSERT command. SQL Server provides several functions to do this: @@Identity provides the last value generated on the current connection, while Scope_Identity(tablename) provides the last value generated, regardless of the connection it was created on.
   Example:
Insert Into Contacts (FirstName, LastName ) Values ('Test', 'User' ) -- Select @@Identity -- OR -- Declare @ID int Select @ID = @@Identity Update Contacts Set Phone = 'XXX-YYY-ZZZZ' Where ContactID = @ID Further Information

Get more info on 'Identity Column'.


External Link Exchanges

Do you know how hard it is to get a link from a large encyclopaedia? Well we're different and will prove it. To get a link from us just add the following HTML to your site on a relevant page:

    <a href="http://identity_column.totallyexplained.com">Identity column Totally Explained</a>

Then simply click through this link from your web page. Our crawlers will verify your link, extract the title of your web page and instantly add a link back to it. If you like you can remove the words Totally Explained and embed the link in article text.
   As long as your link remains in place, we'll keep our link to you right here. Please play fair - our crawlers are watching. Your site must be closely related to this one's topic. Any kind of spamming, dubious practises or removing the link will result in your link from us being dropped and, potentially, your whole site being banned.



Copyright © 2007-8 totallyexplained.com | Licensed under the GNU Free Documentation License | Site Map
This article contains text from the Wikipedia article Identity column (History) and is released under the GFDL | RSS Version